package com.ruicar.afs.cloud.apply.business.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.apply.business.condition.ApplyOrderLeadingCondition;
import com.ruicar.afs.cloud.apply.business.service.ApplyOrderLeadingService;
import com.ruicar.afs.cloud.apply.common.utils.ApplyConstants;
import com.ruicar.afs.cloud.apply.pre.loan.vo.ApplyOrderLeadingVo;
import com.ruicar.afs.cloud.common.core.query.QueryCondition;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import groovy.util.logging.Slf4j;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单放款管理controller
 *
 * @author 耿继辉
 */
@RestController
@Slf4j
@RequestMapping("/orderLeading")
@AllArgsConstructor
@ApiOperation("订单放款管理")
public class ApplyOrderLeadingController {
    private final ApplyOrderLeadingService applyOrderLeadingService;

    /**
     * 多条件查询订单放款信息
     *
     * @return
     */
    @PostMapping("/getOrderLeadingInfo")
    @ApiOperation("多条件查询订单放款信息")
    public IResponse getOrderLeadingInfo(@RequestBody QueryCondition<ApplyOrderLeadingCondition> condition) {
        JSONArray roleArray = SecurityUtils.getUser().getUserExtInfo().getJSONArray("roles");
        if(roleArray != null){
            if(roleArray.toString().indexOf(ApplyConstants.ROLE_ADMIN) > -1){
                return IResponse.success(null);
            }else{
        Page page = new Page(condition.getPageNumber(), condition.getPageSize());
        IPage<List<ApplyOrderLeadingVo>> orderLeadingInfo = applyOrderLeadingService.getOrderLeadingInfo(page, condition.getCondition());
        return IResponse.success(orderLeadingInfo);
            }
        }else{
            return IResponse.fail("此账号未配置权限,请检查账号！");
        }
    }
}
